package com.wandousoushu.jiusen.ui.my

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.wandousoushu.jiusen.MainActivity
import com.wandousoushu.jiusen.MyApplication.Companion.instance
import com.wandousoushu.jiusen.R
import com.wandousoushu.jiusen.ui.login.LoginActivity
import com.wandousoushu.jiusen.util.putPrefString

class AccountManagerActivity : AppCompatActivity() {
    private var phoneTextView: TextView? = null
    private var nickNameTextView: TextView? = null
    private var exitTextView: TextView? = null
    private var nickNameChangeLinearLayout: LinearLayout? = null
    private var pwdChangeLinearLayout: LinearLayout? = null
    private var backLinearLayout: LinearLayout? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_account_manager)
        InitView()
        InitData()
    }

    private fun InitView() {
        backLinearLayout = findViewById(R.id.accoutmanager_ll_back)
        backLinearLayout!!.setOnClickListener(View.OnClickListener { finish() })
        phoneTextView = findViewById(R.id.accoutmanager_tv_phone)
        nickNameTextView = findViewById(R.id.accoutmanager_tv_nichname)
        nickNameChangeLinearLayout = findViewById(R.id.accountmanager_ll_change_nickname)
        nickNameChangeLinearLayout!!.setOnClickListener(View.OnClickListener {
            val intent = Intent(applicationContext, NameChangeActivity::class.java)
            startActivity(intent)
        })
        pwdChangeLinearLayout = findViewById(R.id.accountmanager_ll_change_pwd)
        pwdChangeLinearLayout!!.setOnClickListener(View.OnClickListener {
            val intent = Intent(applicationContext, PasswordChangerActivity::class.java)
            startActivity(intent)
        })
        exitTextView = findViewById(R.id.accountmanager_btn_exit)
        exitTextView!!.setOnClickListener(View.OnClickListener {
            applicationContext.putPrefString("account", "")
            applicationContext.putPrefString("password", "")
            val intent = Intent(applicationContext, LoginActivity::class.java)
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
            startActivity(intent)
        })
    }

    private fun InitData() {
        phoneTextView!!.text = instance.phoneNum
    }

    override fun onResume() {
        super.onResume()
        nickNameTextView!!.text = instance.nickName
    }
}